import subprocess
import re
import os
import signal
# from 721test.src.log import Get_Time
from common.gene_log import Get_Time

now = Get_Time()


class Gene_Trace():
    def __init__(self, com, folder):
        self.com = com
        self.folder = folder

    def start_trace(self):
        print("开始抓trace啦！！")
        trace_obj = subprocess.Popen(["./../bin/diag",self.folder + now,"-","-","%s" % self.com], shell=False)


    def stop_trace(self):
        print("正在关闭trcae")
        trace_objj = subprocess.Popen("ps -e|grep diag", shell=True, stdout=subprocess.PIPE)
        std = trace_objj.stdout.readline(100).decode()
        pid = re.findall(r"\d\d\d\d*",std)
        try:
            os.kill(int(pid[0]),signal.SIGKILL)
        except IndexError as e:
            print("真的没事")
# gt = Gene_Trace("/dev/ttyUSB2")
# gt.stop_trace()


